package service
import (
"time"
"github.com/jcmturner/gokrb5/v8/credentials"
"github.com/jcmturner/gokrb5/v8/iana/errorcode"
"github.com/jcmturner/gokrb5/v8/messages"
)
func VerifyAPREQ (APReq *messages .APReq , s *Settings ) (bool , *credentials .Credentials , error ) {
var creds *credentials .Credentials
ok , err := APReq .Verify (s .Keytab , s .MaxClockSkew (), s .ClientAddress (), s .KeytabPrincipal ())
if err != nil || !ok {
return false , creds , err
}
if s .RequireHostAddr () && len (APReq .Ticket .DecryptedEncPart .CAddr ) < 1 {
return false , creds ,
messages .NewKRBError (APReq .Ticket .SName , APReq .Ticket .Realm , errorcode .KRB_AP_ERR_BADADDR , "ticket does not contain HostAddress values required" )
}
rc := GetReplayCache (s .MaxClockSkew ())
if rc .IsReplay (APReq .Ticket .SName , APReq .Authenticator ) {
return false , creds ,
messages .NewKRBError (APReq .Ticket .SName , APReq .Ticket .Realm , errorcode .KRB_AP_ERR_REPEAT , "replay detected" )
}
c := credentials .NewFromPrincipalName (APReq .Authenticator .CName , APReq .Authenticator .CRealm )
creds = c
creds .SetAuthTime (time .Now ().UTC ())
creds .SetAuthenticated (true )
creds .SetValidUntil (APReq .Ticket .DecryptedEncPart .EndTime )
if !s .disablePACDecoding {
isPAC , pac , err := APReq .Ticket .GetPACType (s .Keytab , s .KeytabPrincipal (), s .Logger ())
if isPAC && err != nil {
return false , creds , err
}
if isPAC {
creds .SetADCredentials (credentials .ADCredentials {
GroupMembershipSIDs : pac .KerbValidationInfo .GetGroupMembershipSIDs (),
LogOnTime : pac .KerbValidationInfo .LogOnTime .Time (),
LogOffTime : pac .KerbValidationInfo .LogOffTime .Time (),
PasswordLastSet : pac .KerbValidationInfo .PasswordLastSet .Time (),
EffectiveName : pac .KerbValidationInfo .EffectiveName .Value ,
FullName : pac .KerbValidationInfo .FullName .Value ,
UserID : int (pac .KerbValidationInfo .UserID ),
PrimaryGroupID : int (pac .KerbValidationInfo .PrimaryGroupID ),
LogonServer : pac .KerbValidationInfo .LogonServer .Value ,
LogonDomainName : pac .KerbValidationInfo .LogonDomainName .Value ,
LogonDomainID : pac .KerbValidationInfo .LogonDomainID .String (),
})
}
}
return true , creds , nil
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .